package com.ggh.jinjilive.ui.mine.zhubo;

import androidx.lifecycle.MutableLiveData;

import com.ggh.jinjilive.mobile.ResultEntity;
import com.ggh.jinjilive.mobile.mine.MembersMobile;
import com.ggh.jinjilive.mobile.mine.zhubo.LiuShuiDetailsModel;
import com.ggh.jinjilive.mobile.mine.zhubo.ZhuBoEarningsMobile;
import com.ggh.jinjilive.mobile.mine.zhubo.ZhuBoStatementMobile;
import com.ggh.jinjilive.remotedata.InterceptObserver;
import com.ggh.jinjilive.remotedata.systemapi.SystemApiService;
import com.ggh.jinjilive.ui.BaseViewModel;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class ZhuBoViewModel extends BaseViewModel {
    //主播收益
    public MutableLiveData<ZhuBoEarningsMobile> mZhuBoEarningsMobile = new MutableLiveData<>();
    //主播报表
    public MutableLiveData<ZhuBoStatementMobile> mZhuBoStatementMobile = new MutableLiveData<>();
    //日期报表
    public MutableLiveData<ZhuBoStatementMobile> mDateZhuBoStatementMobile = new MutableLiveData<>();
    //钻石流水
    public MutableLiveData<List<LiuShuiDetailsModel>> mListLiuShuiDetailsModel = new MutableLiveData<>();

    public ZhuBoViewModel(SystemApiService apiCallInterface) {
        super(apiCallInterface);

    }
    /**
     * 主播收益
     */
    public void AnchorAnchorIncome(){
        addSubscribe(apiCallInterface.AnchorAnchorIncome().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new InterceptObserver<ResultEntity<ZhuBoEarningsMobile>>() {
            @Override
            public void onNextData(ResultEntity resultEntity) {
                ZhuBoEarningsMobile membersMobileList = (ZhuBoEarningsMobile) resultEntity.getData();
                mZhuBoEarningsMobile.setValue(membersMobileList);
            }

            @Override
            public void onErrorNet(Throwable t, String netMsg) {
                mZhuBoEarningsMobile.setValue(null);
            }
        }));
    }
    /**
     * 主播报表
     */
    public void AnchorAuthReport(){
        addSubscribe(apiCallInterface.AnchorAuthReport().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new InterceptObserver<ResultEntity<ZhuBoStatementMobile>>() {
            @Override
            public void onNextData(ResultEntity resultEntity) {
                ZhuBoStatementMobile zhuBoStatementMobile = (ZhuBoStatementMobile) resultEntity.getData();
                mZhuBoStatementMobile.setValue(zhuBoStatementMobile);
            }

            @Override
            public void onErrorNet(Throwable t, String netMsg) {
                mZhuBoEarningsMobile.setValue(null);
            }
        }));
    }
    /**
     * 日报表
     * @param day
     */
    //http://live.hefeiboge.cn/api/Anchor/dayReport
    public void AnchorDayReport(String day){
        Map<String, Object> params = new HashMap<>();
        params.put("day",day);
        addSubscribe(apiCallInterface.AnchorDayReport(params).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new InterceptObserver<ResultEntity<ZhuBoStatementMobile>>() {
            @Override
            public void onNextData(ResultEntity resultEntity) {
                ZhuBoStatementMobile zhuBoStatementMobile = (ZhuBoStatementMobile) resultEntity.getData();
                mDateZhuBoStatementMobile.setValue(zhuBoStatementMobile);
            }

            @Override
            public void onErrorNet(Throwable t, String netMsg) {
                mDateZhuBoStatementMobile.setValue(null);
            }
        }));
    }
    /**
     * 周报表
     * @param week
     */
    //http://live.hefeiboge.cn/api/Anchor/dayReport
    public void AnchorWeekReport(String week){
        Map<String, Object> params = new HashMap<>();
        params.put("week",week);
        addSubscribe(apiCallInterface.AnchorWeekReport(params).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new InterceptObserver<ResultEntity<ZhuBoStatementMobile>>() {
            @Override
            public void onNextData(ResultEntity resultEntity) {
                ZhuBoStatementMobile zhuBoStatementMobile = (ZhuBoStatementMobile) resultEntity.getData();
                mDateZhuBoStatementMobile.setValue(zhuBoStatementMobile);
            }

            @Override
            public void onErrorNet(Throwable t, String netMsg) {
                mDateZhuBoStatementMobile.setValue(null);
            }
        }));
    }
    /**
     * 月报表
     * @param month
     */
    public void AnchorMonyhReport(String month){
        Map<String, Object> params = new HashMap<>();
        params.put("month",month);
        addSubscribe(apiCallInterface.AnchorMonthReport(params).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new InterceptObserver<ResultEntity<ZhuBoStatementMobile>>() {
            @Override
            public void onNextData(ResultEntity resultEntity) {
                ZhuBoStatementMobile zhuBoStatementMobile = (ZhuBoStatementMobile) resultEntity.getData();
                mDateZhuBoStatementMobile.setValue(zhuBoStatementMobile);
            }

            @Override
            public void onErrorNet(Throwable t, String netMsg) {
                mDateZhuBoStatementMobile.setValue(null);
            }
        }));
    }
    /**
     * 钻石流水
     */
    public void AnchorWeekSilverDetail(Map<String, Object> params){
        addSubscribe(apiCallInterface.AnchorWeekSilverDetail(params).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new InterceptObserver<ResultEntity<List<LiuShuiDetailsModel>>>() {
            @Override
            public void onNextData(ResultEntity resultEntity) {
                List<LiuShuiDetailsModel> liuShuiDetailsModelList = (List<LiuShuiDetailsModel>) resultEntity.getData();
                mListLiuShuiDetailsModel.setValue(liuShuiDetailsModelList);
            }

            @Override
            public void onErrorNet(Throwable t, String netMsg) {
                mListLiuShuiDetailsModel.setValue(null);
            }
        }));
    }
}
